package fileDemo.mfile;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Random;

/**
 * @author jie
 * @version 创建时间：2018年11月2日 下午4:08:42
 * 类说明
 */
public class FileCopy {
    public static void main(String[] args) {

        String newFileName = getNewFileName();
        System.out.println(newFileName);
        // todo path: /Users/macpro/ideaWorkSpace/MyJava
        String defaultPath = new File("abc.txt").getAbsoluteFile().getParent();
        File file = new File(defaultPath, newFileName);

        System.out.println(file.exists());
        try {
            file.createNewFile();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public static String getNewFileName() {
        String defaultPath = "C:\\Users\\zy\\Desktop\\";

        File dir = new File(defaultPath);
        if (!dir.exists() || !dir.isDirectory()) {
            dir.mkdirs();
        }
        Random random = new Random();
        String fStr = defaultPath + "defaultVideo" + random.nextInt(10000000) + ".mp4";
        File file = new File(fStr);
        if (!file.exists()) {
            return fStr;
        } else {
            return getNewFileName();
        }
    }

}
